package test;

public enum  StateEnum {
    //使用构造方法创建对象,每一个都是StateEnum的实例
    SUCCESS(1, "成功"),
    FAILED(0, "失败");


    private int state;
    private String stateInfo;

    public int getState() {
        return state;
    }
    public String getStateInfo() {
        return stateInfo;
    }


    StateEnum(int state, String stateInfo){
        this.state = state;
        this.stateInfo = stateInfo;
    }

    /**
     * 根据int类型的index,找到对应StateEnum
     * @param index
     * @return
     */
    public static StateEnum stateOf(int index){
        for (StateEnum state:values()){
            if (state.getState()==index){
                return state;
            }
        }
        return null;
    }

    /**
     * 根据int类型的index,找到对应的String的值
     * @param index
     * @return
     */
    public static String valuesOf(int index){
        for (StateEnum state:values()){
            if (state.getState()==index){
                return state.getStateInfo();
            }
        }
        return "null";
    }


}